<?php
namespace Api\Controller;
use Api\Service\GoodsService;
use Api\Service\OrderService;
use Mobile\Model\focusModel;

class IndexController extends BaseController {

    public function index(){

        $goodsWhere['ischeck']=1;
        $goodsWhere['goods_id']=array(array('NEQ',2),array('NEQ',3),"AND");
        $filed=GoodsService::S()->goodsFiled();
        //$filed.="shop_price";
        $goodsList=GoodsService::S()->queryGoodsInfoByWhere($goodsWhere,$filed);
        foreach ($goodsList as $k=>$v){
            //$goodsList[$k]['shop_price']=$goodsList[$k]["shop_price"];
            $goodsList[$k]['goods_pic']=C('UPYUN_DOMAIN').$goodsList[$k]['goods_pic'];//$goodsList[$k]["grade{$this->member['grade_id']}_price"];
            $thumb=json_decode($v['goods_thumb'],true);//$goodsList[$k]["grade{$this->member['grade_id']}_price"];
            foreach ($thumb as $sk=>$sv){
                $thumb[$sk]=C('UPYUN_DOMAIN').$sv;
            }
            $goodsList[$k]['goods_thumb']=$thumb;
        }
        $data['goodsList']=$goodsList;
        $focModel=M('focus');
        $filed='pic,link';
        $data['focus']=$focModel->field($filed)->where(array('position'=>1))->select();//查询首页轮播图
        foreach ($data['focus'] as $k=>$v){
            $data['focus'][$k]['pic']=C('UPYUN_DOMAIN').$v['pic'];
        }
        $where['checked']=array('in',array(1,2,5));
        $orderinfo=OrderService::S()->queryOrderList($where,1,10,'order_title as title');
        $newArray=array();
        foreach($orderinfo as $k=>$v) {
            $newArray[]= "最新订单:".$v['title'];
        }
        $data['show']=$newArray;
        $this->ajax(200,'success',$data);
    }


    public function makeMoney(){
        $img=C('UPYUN_DOMAIN').C('HOW_MAKE_MONEY');
        $this->ajax(200,'success',$img,'img');
    }


    public function indexClass(){
        /* 分类列表 */
        $typeList = M('goodstype')->field('gtype_name as text,gtype_id as type')->order('gtype_ord asc')->select();
        /* 首页轮播 */
        $where = array(
            "status" => 1,
            "position" => 1
        );
        $focusModel=new focusModel();
        $focus_list = $focusModel->getFocusLists($where);

        foreach($focus_list as $k=>$v) {
            $focus_list[$k]['pic'] = C('UPYUN_DOMAIN').$v['pic'];
            if(strstr($v['link'],'goods_id')){
                $focus_list[$k]['type']='goods';
                $link=explode('?',$v['link']);
                $dt=explode('&',$link[1]);
                $va=explode('=',$dt[0]);
                $value=$va[1];
            }elseif (strstr($v['link'],'mp.weixin.qq.com')){
                $focus_list[$k]['type']='url';
                $value=$v['link'];
            }else{
                $focus_list[$k]['type']='no';
                $value='';
            }
            unset($focus_list[$k]['link']);
            $focus_list[$k]['value']=$value;
        }
        /* 本月新品 */
        $field1 = "concat('".C('UPYUN_DOMAIN')."',month_imgurl) as imgurl,goods_id";
        $field2 = "*,concat('".C('UPYUN_DOMAIN')."',hot_imgurl) as imgurl,goods_id".
            ",goods_name as name";
        $monehList = M('goods')
            ->field($field1)
            ->where(array(
            'is_new' => 1,
            'ischeck' => 1,
            'stock' => array('gt',0),
            '_string' => "(month_imgurl is not null && month_imgurl != '')"
        ))->order('ord asc')->select();

        /* 热卖单品 */
        $hotList = M('goods')
            ->field($field2)
            ->where(array(
            'is_hot' => 1,
            'ischeck' => 1,
            'stock' => array('gt',0),
            '_string' => "(hot_imgurl is not null && hot_imgurl != '')"
        ))->order('ord asc')->page(1,3)->select();
        $hoteNew = array();
        $grade = 1;//max($this->['grade_id'],1);
        foreach($hotList as $k=>$v) {
            $hoteNew[] = array(
                'img' => $v['imgurl'],
                'name' => $v['name'],
                'price' => $v['grade'.$grade.'_price'],
                'market_pri' => $v['market_price'],
                'goods_id'=>$v['goods_id']
            );
        }
        $goodsList[]=array(
            'data'=>$hoteNew,
            'title'=>'最热商品'
        );
        $study=array(
            C('UPYUN_DOMAIN').'/upload/logo/2018-12/26/240711545823347.jpg'//get_domain()."/Static/mobile/index/images/sanjiaoxing.png"
        );
        //$study=array();
        $data = array(
            'swiperList' => $focus_list,
            'monthList' => $monehList,
            'goodsList' =>$goodsList,
            'typeList' => $typeList,
            'study'=>$study
        );
        $this->ajax(200,'success',$data);

    }

    public function index_zkhb(){
        $goods=GoodsService::S()->queryGoodsInfoByWhere(array(),'goods_id,goods_name');
    }



}